package com.batsoft.trade.api.core.shiro.manage;

import org.apache.shiro.session.mgt.SessionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 自定义session管理器
 */
@Configuration
public class SessionManage {

    private static final int SESSION_TIMEOUT = 30 * 60;

    /**
     * 自定义session管理器
     */
    @Bean
    public SessionManager sessionManager(RedisSessionDao redisSessionDAO) {
        WebSessionManager mySessionManager = new WebSessionManager();
        mySessionManager.setGlobalSessionTimeout(SESSION_TIMEOUT * 1000);
        mySessionManager.setSessionDAO(redisSessionDAO);
        return mySessionManager;
    }

    /**
     * redis session
     */
    @Bean
    public RedisSessionDao redisSessionDAO() {
        return new RedisSessionDao(SESSION_TIMEOUT);
    }
}
